package com.jraft;

import com.alipay.remoting.exception.CodecException;
import com.alipay.remoting.serialization.SerializerManager;

import java.io.Serializable;

public class Hession {

    static class A implements Serializable {
        String name;

        @Override
        public String toString() {
            return "A{" +
                    "name='" + name + '\'' +
                    '}';
        }
    }
    public static void main(String[] args) throws Exception {
        A a=new A();

        a.name="zhangsan";

        byte[] serialize = serialize(a);

        Object deserialize = deserialize(serialize, A.class.getName());

        System.out.println("deserialize = " + deserialize);


    }

    static <T> T deserialize(byte[] bytes,String name) throws CodecException {
        return SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(bytes,name);
    }


    static <T> byte[] serialize(T obj) throws CodecException {
        return SerializerManager.getSerializer(SerializerManager.Hessian2).serialize(obj);
    }
}
